package com.jeeplus.modules.api.utils;

public class LocationUtils {

    private static double rad(double d) {
        return d * Math.PI / 180.0;
    }

    public static String getDistance(String lng3, String lat3, String lng4, String lat4) {
        double lng1 = Double.parseDouble(lng3);
        double lat1 = Double.parseDouble(lat3);
        double lng2 = Double.parseDouble(lng4);
        double lat2 = Double.parseDouble(lat4);
        double a = rad(lat1) - rad(lat2);
        double b = rad(lng1) - rad(lng2);
        double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(rad(lat1)) * Math.cos(rad(lat2)) * Math.pow(Math.sin(b / 2), 2)));
        double EARTH_RADIUS = 6378.137;
        s = s * EARTH_RADIUS;
        s = Math.round(s * 10000d) / 10000d;
        s = s * 1000;
        String s1 = String.valueOf(Math.ceil(s));
        return s1.substring(0, s1.length() - 2);
    }
}